package com.hanserwei.mydemo.stream;

import java.util.IntSummaryStatistics;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class EffectiveTest1 {
    public static void main(String[] args) {
        IntStream intStream1 = IntStream.of(97, 98, 99, 100);
        IntStream intStream2 = IntStream.of(97, 98, 99, 100);
        IntStream intStream3 = IntStream.of(97, 98, 99, 100);
        IntStream intStream4 = IntStream.of(97, 98, 99, 100);
        IntStream intStream5 = IntStream.of(97, 98, 99, 100);
        IntStream intStream6 = IntStream.of(97, 98, 99, 100);
        IntStream intStream7 = IntStream.of(97, 98, 99, 100);

        // 转换为对象
        Stream<String> stringStream = intStream1.mapToObj(Character::toString);
        stringStream.forEach(System.out::println);

        // 转换为包装类
        Stream<Integer> integerStream = intStream2.boxed();
        integerStream.forEach(System.out::println);

        // 求和
        int sum = intStream3.sum();
        System.out.println(sum);

        // 求最大值
        intStream4.max().ifPresent(System.out::println);


        // 求最小值
        intStream5.min().ifPresent(System.out::println);


        // 求平均值
        intStream6.average().ifPresent(System.out::println);


        // 综合count，sum， average，max，min
        IntSummaryStatistics statistics = intStream7.summaryStatistics();
        System.out.println(statistics.getMax());
        System.out.println(statistics.getMin());
        System.out.println(statistics.getAverage());
        System.out.println(statistics.getSum());
    }
}
